﻿using System;
using System.Drawing;
using System.Collections.Generic;
using System.Text;
using DirectUI.Mobile.UI.Drawing.GdiPlus;
namespace DirectUI.Mobile.UI.Controls
{
    public class DirectUIMenuItem : DirectUIControl
    {
        public DirectUIMenuItem()
        {
           
        }
        protected override void InitControl()
        {
            base.InitControl();
            this.Height = 20;
            this.ForeColor = Color.Black;
            this.Font = new Font(FontFamily.GenericSerif, 10, FontStyle.Regular);
            FocusColor = Color.Orange;
        }
        public DirectUIMenuItem(string text, string value)
        {
            this.Text = text;
            this.Value = value;
          
        }
        public override bool Active
        {
            get
            {
                return true;
            }
        }
        public string Text
        {
            get;
            set;
        }
        public string Value
        {
            get;
            set;
        }
        private SolidBrush brush = new SolidBrush(Color.Black);
        public Color ShadowColor { get; set; }
        public override void OnPaint(DirectUIPaintEventArgs e)
        {
            base.OnPaint(e);
            //     e.Graphics.FillRectangle(new SolidBrush(this.BackColor), e.ControlBounds);

            if (!string.IsNullOrEmpty(Text))
            {
                PaintDefaultText(e, Text);
            }
        }
        public Color FocusColor { get; set; }
        private Color originBackColor;
        public override void OnDown(PointEventArgs e)
        {
            base.OnDown(e);
            originBackColor = this.backColor;
         
                this.BackColor = FocusColor;
         
        }
        public override void OnUp(PointEventArgs e)
        {
            base.OnUp(e);
         
           this.BackColor = originBackColor;
           
        }
        protected void PaintDefaultText(DirectUIPaintEventArgs e, string text)
        {
            Graphics g = e.Graphics;
            Rectangle bounds = e.ControlBounds;
            bounds.Inflate(e.ScaleX(-3), e.ScaleY(-1));
            //bounds.Y += e.ScaleY(-1);
            if (bounds.Height > 0 && bounds.Width > 0)
            {
                if (ShadowColor.IsEmpty)
                {
                    brush.Color = Enabled ? ForeColor : Color.Silver;
                    Font font = new Font(FontFamily.GenericSerif, 14, FontStyle.Bold);

                    RectangleF recf = new RectangleF(bounds.X+20, bounds.Y, bounds.Width, bounds.Height - 3);
                    g.DrawString(text, font, brush, recf);
                    g.DrawLine(new Pen(Color.Black, 1f), bounds.X, bounds.Y + bounds.Height - 1, bounds.X+bounds.Width, bounds.Y + bounds.Height - 1);

                }
                else
                {
                    DirectUI.Mobile.UI.Drawing.GdiPlus.GdiExt.DrawStringShadow(g, text, Font, ForeColor, ShadowColor, bounds, new StringFormat());
                }
            }
        }
    }

}
